package me.moscrop.RootCommand.listeners;

import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EndermanPickupEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;

import me.moscrop.RootCommand.commands.Back;
import me.moscrop.RootCommand.commands.God;


public class RCEntityListener extends EntityListener {

	public void onEntityDamage (EntityDamageEvent event) {
		if (event.isCancelled())
	            return;
	        
		if (event.getEntity() instanceof Player) {
			Player playerName = ((Player) event.getEntity());
			if (God.isGod(playerName))
				event.setCancelled(true);
				
	        }
	}
	
	@Override
	public void onFoodLevelChange(FoodLevelChangeEvent event) {
		if(event.getEntity() instanceof Player) {
			Player playerName = (Player) event.getEntity();
			if (God.isGod(playerName))
				playerName.setFoodLevel(20);  
		}
	}
		  
	@Override
	public void onEntityDeath(EntityDeathEvent event) {
		//get the user from the event
		Entity entity = event.getEntity();
		//check there a human
		if (entity instanceof Player) {
			//Put that players name and location in the Map
			Back.saveLastLocation(((Player) entity), entity.getLocation());
			  ((Player) entity).sendMessage("Use the /back command to go your last destination");
		}
			
		if (event instanceof PlayerDeathEvent) {
			PlayerDeathEvent e = (PlayerDeathEvent) event;
			e.setDeathMessage(null);
			e.setDroppedExp(0);
		}				
	}  	
	
	public void processDamageEvent(EntityDamageEvent event) {
		
		Entity entitydamager = null;
		
		/* Moving to another file !!! */
		
		 switch (event.getCause()) {
			case PROJECTILE:
		 	case ENTITY_ATTACK:
		 		//Mob?
			break;
		 	
		 	case BLOCK_EXPLOSION:		 		
		 	break;
		 		
		 	case ENTITY_EXPLOSION:
		 		if (entitydamager instanceof TNTPrimed) {
		 			
		 		} else if (entitydamager instanceof Fireball) {
		 			
		 		} else {
		 			//creeper?
		 		}
		 	break;
		 		
		 	case CONTACT:				 
			break;
			
			case FALL:				
			break;
			
			case FIRE_TICK:
			case FIRE:			  
			break; //On fire!
						
			case DROWNING:				
			break;
			
			case LAVA:	
			break;
			
			case SUFFOCATION:
			break;
			
			case VOID:
			break;
			
			case LIGHTNING:
			break;
			
			case SUICIDE:
			break;
			
			case STARVATION:
			break;
			
			default:
			break;//Sucked into another dimension / Arron has them / Who knows or cares?
		 }
	}
	
	public void onEndermanPickup(EndermanPickupEvent event){
		if(event.isCancelled()){
			return;
		}
		event.setCancelled(true);
	}
	
}
	
